package com.ruoyi.web.controller.airplane;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.domain.TbDevice;
import com.ruoyi.system.domain.dto.ItemDTO;
import com.ruoyi.system.domain.dto.TbDataPackageCreateDTO;
import com.ruoyi.system.domain.vo.TbDataPackageVO;
import com.ruoyi.system.domain.vo.TbDeviceInfoVO;
import com.ruoyi.system.domain.vo.TbDeviceVO;
import com.ruoyi.system.domain.vo.TbTaskDetailVO;
import com.ruoyi.system.service.ITbDeviceAppsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbDataPackage;
import com.ruoyi.system.service.ITbDataPackageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据包信息Controller
 *
 * @author ruoyi
 * @date 2025-07-23
 */
@Api(tags = "数据包信息")
@RestController
@RequestMapping("/system/package")
public class TbDataPackageController extends BaseController {
    @Autowired
    private ITbDataPackageService tbDataPackageService;

    @Autowired
    private ITbDeviceAppsService tbDeviceAppsService;

    /**
     * 查询数据包信息列表
     */
    //  @PreAuthorize("@ss.hasPermi('system:package:list')")
    @ApiOperation("查询数据包信息列表")
    @GetMapping("/list")
    public TableDataInfo list(TbDataPackageVO tbDataPackage) {
        startPage();
        List<TbDataPackage> list = tbDataPackageService.selectTbDataPackageList(tbDataPackage);
        return getDataTable(list);
    }


    @ApiOperation("查询数据包信息列表/不分页")
    @GetMapping("/lis")
    public R<List<TbDataPackage>> lis(TbDataPackageVO tbDataPackage) {
        List<TbDataPackage> list = tbDataPackageService.selectTbDataPackageList(tbDataPackage);
        return R.ok(list);
    }

    /**
     * 导出数据包信息列表
     */
    //@PreAuthorize("@ss.hasPermi('system:package:export')")
//    @ApiOperation("导出数据包信息列表")
//    @Log(title = "数据包信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, TbDataPackage tbDataPackage) {
//        List<TbDataPackage> list = tbDataPackageService.selectTbDataPackageList(tbDataPackage);
//        ExcelUtil<TbDataPackage> util = new ExcelUtil<TbDataPackage>(TbDataPackage.class);
//        util.exportExcel(response, list, "数据包信息数据");
//    }

    /**
     * 获取数据包信息详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:package:query')")
    @ApiOperation("获取数据包信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tbDataPackageService.selectTbDataPackageById(id));
    }

    /**
     * 新增数据包信息
     */
    // @PreAuthorize("@ss.hasPermi('system:package:add')")
    @ApiOperation("新增数据包信息")
    @Log(title = "数据包信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody TbDataPackageCreateDTO dto) {

        return  tbDataPackageService.insertTbDataPackage(dto);
    }

    /**
     * 修改数据包信息
     */
    //  @PreAuthorize("@ss.hasPermi('system:package:edit')")
    @ApiOperation("修改数据包信息")
    @Log(title = "数据包信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDataPackage tbDataPackage) {
        return toAjax(tbDataPackageService.updateTbDataPackage(tbDataPackage));
    }

    /**
     * 删除数据包信息
     */
    @ApiOperation("删除数据包信息")
    // @PreAuthorize("@ss.hasPermi('system:package:remove')")
    @Log(title = "数据包信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbDataPackageService.deleteTbDataPackageByIds(ids));
    }


    @ApiOperation("对应版本的应用关联的任务列表")
    //  @PreAuthorize("@ss.hasPermi('system:apps:remove')")
    @PostMapping("/versionCode/taskDetail")
    public TableDataInfo listTaskBypackageVersioncode(@RequestBody ItemDTO dto) {
        startPage();

        List<TbTaskDetailVO> list = tbDeviceAppsService.listTaskBypackageVersioncode(dto);

        return getDataTable(list);

    }

}
